use fluffy::{DbRow, model::Model,};
use super::ModelBackend;
use serde_derive::{Serialize};
use crate::validations::Validator;
use std::collections::HashMap;
//use chrono::{NaiveDateTime};

#[derive(Default, Debug, Serialize)]
pub struct AppInfo {
    pub id: usize, //编号
    pub app_name: String, //名称
    pub app_icon: String, //备注
    pub customers_id: u32, //
    pub app_host:String,
//    pub created_at:NaiveDateTime,
//    pub updated_at:String,
//    pub expired_at:String,
    pub app_id: String,
}

impl Model for AppInfo {
    fn get_table_name() -> &'static str { "manage_app_info" }
}

impl ModelBackend for AppInfo {

    type M = Self;

    get_fields!(Self, [
        app_name => String,
        app_icon => String,
        customers_id => u32,
        app_host => String,
//        created_at => NaiveDateTime,
//        updated_at => String,
//        expired_at => String,
        app_id => String,

    ]);

    fn validate(data: &HashMap<String, String>) -> Result<(), String> {
     Validator::load(&data).string_length("app_name", "分类名称必须在2-20之间", 2, 20, true)
            .string_limit("app_icon", "备注长度必须在0-50之间", 50)
//            .is_numeric("customers_id", "排序必须是有效的数字")
            .validate()
    }

}
